#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>

#define MAXLINE 10

int main(int argc, char *argv[])
{
    int connfd;
    struct sockaddr_in serveraddr;
    char line[MAXLINE] = "123456789";

    connfd = socket(PF_INET, SOCK_STREAM, 0);

    memset(&serveraddr, 0, sizeof(serveraddr));
    serveraddr.sin_family = AF_INET;
    inet_aton("127.0.0.1", &serveraddr.sin_addr);
    serveraddr.sin_port = htons(5555);

    if (connect(connfd, (struct sockaddr *)&serveraddr, 
            sizeof(serveraddr)) < 0)
        perror("connect error");

    while (fgets(line, MAXLINE, stdin) != NULL) {
        write(connfd, line, MAXLINE);
        read(connfd, line, MAXLINE);    
        printf("%s", line);
    }

    return 0;
}
